package service

import (
	"zimuzu_cvn_web_api/model"
	"zimuzu_cvn_web_api/pkg/e"
)

// Auth:hzp
// 写升级，变更日志
// from = 1     1-会员经销商，2-路由经销商
// action = 1   操作，1-开通，2-续费，3-升级 ，4-到期，5-后台关闭
func AddAgentApplyLog(uid int64, level int, price float64, from, action int) {

	agentInfo, err := model.GetAgentInfoByUid(uid)
	if err != nil {
		e.Log("err", "写升级，变更日志失败：", err.Error())
		return
	}

	var logModel model.AgentInfoLog
	logModel.Uid = uid
	logModel.Type = from
	logModel.Price = price
	logModel.Action = action
	logModel.BeforeTime = agentInfo.ExpireTime
	logModel.BeforeLevel = agentInfo.Level
	logModel.AfterTime = agentInfo.ExpireTime
	logModel.AfterLevel = level
	err = model.AddAgentUserLog(logModel)
	if err != nil {
		e.Log("err", "写日志失败：", err.Error())
		return
	}
	return
}
